home *** CD-ROM | disk | FTP | other *** search
- Path: pangea.Stanford.EDU!karish
- From: karish@pangea.Stanford.EDU (Chuck Karish)
- Newsgroups: comp.lang.c
- Subject: Re: Q: "Overlapping Objects"
- Date: 16 Apr 1996 17:17:49 GMT
- Organization: Mindcraft, Inc.
- Message-ID: <4l0knt$lr1@nntp.Stanford.EDU>
- References: <31714280.201A@micromedia.on.ca> <4ks0lo$b1n@inet-nntp-gw-1.us.oracle.com> <31739F0E.69B6@micromedia.on.ca>
- NNTP-Posting-Host: pangea.stanford.edu
-
- In article <31739F0E.69B6@micromedia.on.ca>,
- David Williams <dwilliam@micromedia.on.ca> wrote:
- >Given
- >
- > char s[]="abcdefghijklmnop";
- > char *sp1=&s[2];
- > char *sp2=&s[4];
- >
- >if you strcpy(sp1,sp2) [not strcat(), as below], will the results be
- >as expected ("abefghijklmnop"), or will there be problems because the copy
- >is copying over part of what it was originally copying from?
-
- The Standard C prototype for strcpy() looks like:
-
- char *strcpy(char *s1, const char *s2);
-
- This guarantees that the data pointed to by s2 will not be
- modified by the call to strcpy(). Since this guarantee
- cannot be fulfilled if the strings overlap as shown above,
- the description of strcpy() says:
-
- If copying takes place between objects that ovewrlap, the
- behavior is undefined.
-
- The exact mechanism by which the strcpy is done is not specified
- in any standard I know of. That means that while this code
- will probably work on some systems, it's not guaranteed to
- work everywhere.
- --
-
- Chuck Karish karish@mindcraft.com
- (415) 323-9000 x117 karish@pangea.stanford.edu
-